package com.study.d4_coll_nature;

import java.util.StringJoiner;

public  class MyLinkedList<T> {
    private int size = 0;
    MyLinkedList.Node<T> first;
    public static class Node<T>{
        T item;
        Node<T> next;

        public Node(T item, Node<T> next) {
            this.item = item;
            this.next = next;
        }
    }
    public boolean add(T t){
        Node<T> newNode = new Node<>(t,null);
        if(first==null){
            first=newNode;
        }else{
            Node<T> temp = first;
            while(temp.next!=null){
                temp=temp.next;
            }
            temp.next=newNode;
        }
        size++;
        return true;
    }
    @Override
    public String toString() {
        StringJoiner sb = new StringJoiner(",","[","]");
        Node<T> temp = first;
        while(temp!=null){
            sb.add(temp.item+"");
            temp=temp.next;
        }
        return sb.toString();
    }
}
class Test2{
    public static void main(String[] args) {
        MyLinkedList<String> mll = new MyLinkedList<>();
        mll.add("哈哈");
        mll.add("java");
        mll.add("c++");
        System.out.println(mll);
    }
}
